package logic

import (
	"context"

	"monitor/api/internal/svc"
	"monitor/api/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
	pb "monitor/rpc/status/status"
)

type CmdSetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCmdSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) CmdSetLogic {
	return CmdSetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CmdSetLogic) CmdSet(req types.CmdSetReq) (*types.CmdSetResp, error) {
	// todo: add your logic here and delete this line
	resp, err := l.svcCtx.Status.CmdSet(l.ctx, &pb.CmdSetReq{Sn: req.Sn, Cmd: int32(req.Cmd), Expire: int32(req.Expire)})
	if err != nil {
		return nil, err
	}
	return &types.CmdSetResp{Code: int(resp.Code), Msg: resp.Msg}, nil
}
